package com.ruoyi.labdata.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.labdata.domain.LabCasType;
import com.ruoyi.labdata.service.ILabCasTypeService;

/**
 * 危化品名录Controller
 * 
 * @author malang
 * @date 2022-03-06
 */
@RestController
@RequestMapping("/labdata/casType")
public class LabCasTypeController extends BaseController {
	@Autowired
	private ILabCasTypeService labCasTypeService;

	/**
	 * 查询危化品名录列表
	 * 
	 */
	@PreAuthorize("@ss.hasPermi('labdata:casType:query')")
	@GetMapping("/list")
	public TableDataInfo list(LabCasType labCasType) {
		startPage();
		List<LabCasType> list = labCasTypeService.selectLabCasTypeList(labCasType);
		return getDataTable(list);
	}

	/**
	 * 公共资源不设权限
	 * 
	 * @param casNo
	 * @return
	 */
	// @PreAuthorize("@ss.hasPermi('labdata:casType:query')")
	@GetMapping(value = "/getData/{casNo}")
	public AjaxResult getLabCasType(@PathVariable("casNo") String casNo) {
		LabCasType labCasType = new LabCasType();
		labCasType.setCasNo(casNo);
		// labCasType.setStatusOpt(Long.valueOf(1));
		List<LabCasType> list = labCasTypeService.selectLabCasTypeList(labCasType);
		return AjaxResult.success(list.size() == 1 ? list.get(0) : null);
	}

	/**
	 * 导出危化品名录列表
	 */
	// @PreAuthorize("@ss.hasPermi('labdata:casType:export')")
	/*
	 * @Log(title = "危化品名录", businessType = BusinessType.EXPORT)
	 * 
	 * @GetMapping("/export") public AjaxResult export(LabCasType labCasType) {
	 * List<LabCasType> list =
	 * labCasTypeService.selectLabCasTypeList(labCasType); ExcelUtil<LabCasType>
	 * util = new ExcelUtil<LabCasType>(LabCasType.class); return
	 * util.exportExcel(list, "casType"); }
	 */

	/**
	 * 获取危化品名录详细信息
	 */
	@PreAuthorize("@ss.hasPermi('labdata:casType:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return AjaxResult.success(labCasTypeService.selectLabCasTypeById(id));
	}

	/**
	 * 新增危化品名录
	 */
	@PreAuthorize("@ss.hasPermi('labdata:casType:edit')")
	@Log(title = "危化品名录", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody LabCasType labCasType) {
		return toAjax(labCasTypeService.insertLabCasType(labCasType));
	}

	/**
	 * 修改危化品名录
	 */
	@PreAuthorize("@ss.hasPermi('labdata:casType:edit')")
	@Log(title = "危化品名录", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody LabCasType labCasType) {
		return toAjax(labCasTypeService.updateLabCasType(labCasType));
	}

	/**
	 * 删除危化品名录
	 */
	@PreAuthorize("@ss.hasPermi('labdata:casType:edit')")
	@Log(title = "危化品名录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(labCasTypeService.deleteLabCasTypeByIds(ids));
	}
}
